﻿#region 命名空间

using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WinnerCMS.BLL.PageFactory.ManageHtml;
using WinnerCMS.Common;
using WinnerCMS.Data;
using WinnerCMS.Model;

#endregion

namespace WinnerCMS.BLL
{
    /// <summary>
    /// SoftManage 的摘要说明。
    /// </summary>
    public partial class SoftManage : MarshalByRefObject
    {
        private static readonly SoftDal Dal = new SoftDal();

        #region 添加软件

        /// <summary>
        /// 添加软件
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [Logging]
        public Result Add(Soft model)
        {
            Result res = new Result();
            if (model.ContentTitle.Length == 0)
            {
                res.Errors = "请添加了标题以后再添加！";
                return res;
            }

            if (model.Content.Trim().Length == 0)
            {
                res.Errors = "请填写了内容以后再添加！";
                return res;
            }

            if (CategoryManage.CheckAllowCategory(model.CategoryId) == false)
            {
                res.Errors = "您没有该栏目的录入权限！";
                return res;
            }

            if (model.Brief.Length == 0)
                model.Brief = MyString.Left(HTML.NoHtml(model.Content), 255);

            if (model.Id == 0)
            {
                model.Id = Dal.Add(model);

                //保存Tags
                new TagsManage().Add(model, UserManage.Current.UserID);

                MakeSinglePage.ContentPageHTML(model.Id);


                res.LogMessage = "添加软件，Id=" + model.Id;
                return res;
            }
            //先删除，保证了各种情况都满足
            DeleteHTML.ContentPage(model.Id);


            Dal.Edit(model);

            //保存Tags
            new TagsManage().Add(model, UserManage.Current.UserID);

            MakeSinglePage.ContentPageHTML(model.Id);


            res.LogMessage = "修改软件，Id=" + model.Id;
            return res;
        }

        #endregion

        #region 软件加载

        /// <summary>
        /// 软件加载
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Soft GetInfo(int id)
        {
            return Dal.GetInfo(id);
        }

        #endregion
    }
}